<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>360搜索</title>
    <style>
        li{
            list-style: none;
        }
        h1{
        	text-align: center;
        }
        #content{
        	width: 500px;
        	margin: 0 auto;
        }
        input{
        	width:100%;
        	height: 50px;
        }
        ul{
        	padding-left:10px;
        }
    </style>
</head>
<body>
   	<h1>360搜索</h1>
    <div id="content">
	    <input type="text" name="name" placeholder="输入你的关键词">
	    <ul></ul>
    </div>
    <script>
        var inp = document.getElementsByName('name')[0];
        var ul = document.getElementsByTagName('ul')[0];
        var soso = 'https://sug.so.360.cn/suggest?callback=suggest_so&encodein=utf-8&encodeout=utf-8&format=json&fields=word,obdata&word=';
        var soso2 = 'https://www.so.com/s?ie=utf-8&shb=1&src=home_so.com&q=';
        inp.onkeyup = function(){
            so();
        }
        function so(){
            var url= soso + inp.value;
            var sc = document.createElement('script');
            sc.src = url;
            //将src放入head
            var head = document.getElementsByTagName('head')[0];
            head.appendChild(sc);
        }
        function suggest_so(text){
            //console.log(text.result);
            var content = '';
            for(var i=0;i<text.result.length;i++){
                    var a = soso2 + text.result[i]['word'];
                    content += '<li><a href= "'+ a +'" target="_blank">'+text.result[i]['word']+'</a></li>';
            }
            ul.innerHTML = content;
        }
    </script>
</body>
</html>